package org.haptimap.hcimodules.touchovermap;

import java.util.LinkedList;
import java.util.List;

import android.graphics.Point;
import android.location.Location;

public class Line {
	private List<Location> elements;
	private String name = "Unnamed Path";
	
	public Line() {
		this.elements = new LinkedList<Location>();
	}
	
	public void setElements(List<Location> elements) {
		this.elements = elements;
	}
	
	public List<Location> getElements() {
		return this.elements;
	}
	
	public void addElement(Location location) {
		if (this.elements != null) {
			this.elements.add(location);
		}
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getName() {
		return this.name;
	}
	
	public List<Point> getElementsAsDisplayCoordinatesIfCloseToPoint(Projection proj,
			Point point, int distance) {
		List<Point> retVal = new LinkedList<Point>();
		for(Location l : this.elements) {
			Point p = new Point();
			proj.toPixels(l, p);
			
			if(this.distanceInScreenPix(point, p)<=distance) {
				retVal.add(p);
			}
		}
		return retVal;
	}
	
	public static int distanceInScreenPix(Point a, Point b) {
		return (int)(Math.sqrt(((a.x-b.x)*(a.x-b.x))+((a.y-b.y)*(a.y-b.y))));
	}
	
	public List<Point> getElementsAsDisplayCoordinates(Projection proj) {
		List<Point> retVal = new LinkedList<Point>();
		for(Location l : this.elements) {
			Point p = new Point();
			proj.toPixels(l, p);
			retVal.add(p);
		}
		return retVal;
	}
}
